#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>

void printa(int a[23][23]) {
    for (int i = 0; i < 23; i++) {
        for (int j = 0; j < 23; j++) {
            printf("%d", a[i][j]);
        }
        printf("\n");
    }
}

int main() {
    int a[23][23] = { 0 };
    int k[400] = { 0 };
    int m, n, i, j, x, o, p;
    char tmp[23][23] = { '\0' };
    scanf("%d %d", &m, &n);
    for (i = 1; i <= m; i++) {
        scanf("%s", &tmp[i]);
        for (j = 0; j < n; j++) {
            
            if (tmp[i][j]== '#')
                a[i][j+1] = 2;
        }
    }
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
            printf("%c", tmp[i][j]);
        }
        printf("\n");
    }



    scanf("%d", &x);
    for (i = 0; i < x; i++) {
        scanf("%d %d", &o, &p);
        if (a[o + 1][p + 1] > 0) {
            a[o + 1][p + 1] -= 2;
            if (a[o + 1][j + 1] <= 0)
                k[i]++;
        }
        if (a[o][p + 1] > 0) {
            a[o][j + 1]--;
            if (a[o][j + 1] <= 0)
                k[i]++;
        }
        if (a[o + 2][p + 1] > 0) {
            a[o + 2][j + 1]--;
            if (a[o + 2][j + i] <= 0)
                k[i]++;
        }
        if (a[o + 1][p] > 0) {
            a[o + 1][j]--;
            if (a[o + 1][j] <= 0)
                k[i]++;
        }
        if (a[o + 1][p + 2] > 0) {
            a[o + 1][j + 2]--;
            if (a[o + 1][j + 2] <= 0)
                k[i]++;
        }

        

    }

    for (i = 0; i < x; i++) {
            printf("ii:%d", k[i]);
        }

    return 0;
}




/*#include<stdio.h>
int main(void)
{
    int a[3][3], i, j, k, sum = 0, count = 0;
    for (i = 0; i < 3; i++)
        for (j = 0; j < 3; j++)

            scanf("%d", &a[i][j])
            ;
    for (i = 0; i < 3; i++)
        for (j = 0; j < 3; j++)
        {
            k = i + j;
            if (
                k == 3
                )
            {
                printf("%d\n", a[i][j]);

                sum += a[i][j]
                    ;

                count++
                    ;
            }
        }
    printf("average=%.2lf\n",
        (double)sum / count
    );
    return 0;
}*/


